/*
*                             ______ _____  _______ 
* .-----..--.--..----..-----.|   __ \     \|    ___|
* |  _  ||  |  ||   _||  -__||    __/  --  |    ___|
* |   __||_____||__|  |_____||___|  |_____/|___|    
* |__|
* $Id: Utilities.as 238 2010-01-31 10:49:33Z alessandro.crugnola $
* $Author Alessandro Crugnola $
* $Rev: 238 $ $LastChangedDate: 2010-01-31 10:49:33 +0000 (Sun, 31 Jan 2010) $
* $URL: http://purepdf.googlecode.com/svn/branches/importer/src/org/purepdf/utils/Utilities.as $
*
* The contents of this file are subject to  LGPL license 
* (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the
* provisions of LGPL are applicable instead of those above.  If you wish to
* allow use of your version of this file only under the terms of the LGPL
* License and not to allow others to use your version of this file under
* the MPL, indicate your decision by deleting the provisions above and
* replace them with the notice and other provisions required by the LGPL.
* If you do not delete the provisions above, a recipient may use your version
* of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the License.
*
* The Original Code is 'iText, a free JAVA-PDF library' ( version 4.2 ) by Bruno Lowagie.
* All the Actionscript ported code and all the modifications to the
* original java library are written by Alessandro Crugnola (alessandro@sephiroth.it)
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the MPL as stated above or under the terms of the GNU
* Library General Public License as published by the Free Software Foundation;
* either version 2 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU LIBRARY GENERAL PUBLIC LICENSE for more
* details
*
* If you didn't download this code from the following link, you should check if
* you aren't using an obsolete version:
* http://code.google.com/p/purepdf
*
*/
package org.purepdf.utils
{
	public class Utilities
	{
		public static function isSurrogateHigh( c: int ): Boolean
		{
			return c >= 55296 /*'\ud800'*/ && c <= 56319 /*'\udbff'*/;
		}
		
		public static function isSurrogateLow( c: int ): Boolean
		{
			return c >= 56320 /*'\udc00'*/ && c <= 57343 /*'\udfff'*/;
		}
	
		public static function isSurrogatePair( text: Vector.<int>, idx: int ): Boolean
		{
			if( idx < 0 || idx > text.length - 2 )
				return false;
			return isSurrogateHigh(text[idx]) && isSurrogateLow(text[idx + 1]);	
		}
		
		public static function isSurrogatePair2( text: String, idx: int ): Boolean
		{
			if (idx < 0 || idx > text.length - 2)
				return false;
			return isSurrogateHigh( text.charCodeAt(idx)) && isSurrogateLow( text.charCodeAt(idx + 1) );
		}
		
		public static function convertToUtf32( highSurrogate: int, lowSurrogate: int ): int
		{
			return (((highSurrogate - 0xd800) * 0x400) + (lowSurrogate - 0xdc00)) + 0x10000;
		}
		
		public static function convertToUtf32_2( text: String, idx: int ): int
		{
			return (((text.charCodeAt(idx) - 0xd800) * 0x400) + (text.charCodeAt(idx + 1) - 0xdc00)) + 0x10000;
		}
		
		public static function convertToUtf32_3( text: Vector.<int>, idx: int ): int
		{
			return (((text[idx] - 0xd800) * 0x400) + (text[idx + 1] - 0xdc00)) + 0x10000;
		}
		
		public static function addToArray( original: Vector.<Vector.<Object>>, item: Vector.<Object> ): Vector.<Vector.<Object>>
		{
			if( original == null )
			{
				original = new Vector.<Vector.<Object>>(1);
				original[0] = item;
				return original;
			} else 
			{
				var original2: Vector.<Vector.<Object>> = original.concat();
				original2.push( item );
				return original2;
			}
		}

	}
}